]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
ShellGlobal: improve code to emit sound events
authorGiovanni Campagna <gcampagna@src.gnome.org>
Sun, 4 Nov 2012 18:53:49 +0000 (19:53 +0100)
committerGiovanni Campagna <gcampagna@src.gnome.org>
Mon, 21 Jan 2013 17:03:23 +0000 (18:03 +0100)
Use libcanberra-gtk3 and improve the set of context properties to correctly
associate the sounds with the shell.

https://bugzilla.gnome.org/show_bug.cgi?id=642831

configure.ac
js/ui/components/automountManager.js
js/ui/status/volume.js
src/shell-global.c
src/shell-global.h

index 119b851ca9f59ddc6a762e9bbe135ff7cd8ac416..1ffde2257de1ba9c7b080b0e0feabd0746979140 100644 (file)
@@ -93,7 +93,7 @@ PKG_CHECK_MODULES(GNOME_SHELL, gio-unix-2.0 >= $GIO_MIN_VERSION
                               clutter-glx-1.0 >= $CLUTTER_MIN_VERSION
                                libstartup-notification-1.0 >= $STARTUP_NOTIFICATION_MIN_VERSION
                                gobject-introspection-1.0 >= $GOBJECT_INTROSPECTION_MIN_VERSION
-                              libcanberra
+                              libcanberra libcanberra-gtk3
                                telepathy-glib >= $TELEPATHY_GLIB_MIN_VERSION
                                telepathy-logger-0.2 >= $TELEPATHY_LOGGER_MIN_VERSION
                                polkit-agent-1 >= $POLKIT_MIN_VERSION xfixes
index 9081e80e6f69bd980b5b729dd50424ba9d36e0a1..e7c426de177f9f7c820f622f965015450136efd7 100644 (file)
@@ -88,7 +88,9 @@ const AutomountManager = new Lang.Class({
         if (!this._loginManager.sessionActive)
             return;
 
-        global.play_theme_sound(0, 'device-added-media');
+        global.play_theme_sound(0, 'device-added-media',
+                                _("External drive connected"),
+                                null);
     },
 
     _onDriveDisconnected: function() {
@@ -97,7 +99,9 @@ const AutomountManager = new Lang.Class({
         if (!this._loginManager.sessionActive)
             return;
 
-        global.play_theme_sound(0, 'device-removed-media');        
+        global.play_theme_sound(0, 'device-removed-media',
+                                _("External drive disconnected"),
+                                null);
     },
 
     _onDriveEjectButton: function(monitor, drive) {
index b08f3d6ff619f49139e7b3d4a592717c65e05969..b25060cfa7bbc5b84e9e6b6b0a12774a6b92a402 100644 (file)
@@ -119,7 +119,10 @@ const StreamSlider = new Lang.Class({
 
     _notifyVolumeChange: function() {
         global.cancel_theme_sound(VOLUME_NOTIFY_ID);
-        global.play_theme_sound(VOLUME_NOTIFY_ID, 'audio-volume-change');
+        global.play_theme_sound(VOLUME_NOTIFY_ID,
+                                'audio-volume-change',
+                                _("Volume changed"),
+                                Clutter.get_current_event ());
     },
 
     _updateVolume: function() {
index af7b4ae805f74f74d433fe92e56c51599b68b1ca..32da177abf8a230646d23fea0b1fb06fc927e558 100644 (file)
 #ifdef HAVE_SYS_RESOURCE_H
 #include <sys/resource.h>
 #endif
+#include <locale.h>
 
 #include <X11/extensions/Xfixes.h>
 #include <canberra.h>
+#include <canberra-gtk.h>
 #include <clutter/glx/clutter-glx.h>
 #include <clutter/x11/clutter-x11.h>
 #include <gdk/gdkx.h>
@@ -265,8 +267,13 @@ shell_global_init (ShellGlobal *global)
 
   global->input_mode = SHELL_STAGE_INPUT_MODE_NORMAL;
 
-  ca_context_create (&global->sound_context);
-  ca_context_change_props (global->sound_context, CA_PROP_APPLICATION_NAME, PACKAGE_NAME, CA_PROP_APPLICATION_ID, "org.gnome.Shell", NULL);
+  global->sound_context = ca_gtk_context_get ();
+  ca_context_change_props (global->sound_context,
+                           CA_PROP_APPLICATION_NAME, "GNOME Shell",
+                           CA_PROP_APPLICATION_ID, "org.gnome.Shell",
+                           CA_PROP_APPLICATION_ICON_NAME, "start-here",
+                           CA_PROP_APPLICATION_LANGUAGE, setlocale (LC_MESSAGES, NULL),
+                           NULL);
   ca_context_open (global->sound_context);
 
   if (!shell_js)
@@ -1577,21 +1584,99 @@ shell_global_run_at_leisure (ShellGlobal         *global,
     schedule_leisure_functions (global);
 }
 
+static void
+build_ca_proplist_for_event (ca_proplist  *props,
+                             const char   *event_id,
+                             const char   *event_description,
+                             ClutterEvent *for_event)
+{
+  ca_proplist_sets (props, CA_PROP_EVENT_ID, event_id);
+  ca_proplist_sets (props, CA_PROP_EVENT_DESCRIPTION, event_description);
+  ca_proplist_sets (props, CA_PROP_CANBERRA_CACHE_CONTROL, "volatile");
+
+  if (for_event)
+    {
+      if (clutter_event_type (for_event) != CLUTTER_KEY_PRESS &&
+          clutter_event_type (for_event) != CLUTTER_KEY_RELEASE)
+        {
+          ClutterPoint point;
+
+          clutter_event_get_position (for_event, &point);
+
+          ca_proplist_setf (props, CA_PROP_EVENT_MOUSE_X, "%d", (int)point.x);
+          ca_proplist_setf (props, CA_PROP_EVENT_MOUSE_Y, "%d", (int)point.y);
+        }
+
+      if (clutter_event_type (for_event) == CLUTTER_BUTTON_PRESS ||
+          clutter_event_type (for_event) == CLUTTER_BUTTON_RELEASE)
+        {
+          gint button;
+
+          button = clutter_event_get_button (for_event);
+          ca_proplist_setf (props, CA_PROP_EVENT_MOUSE_BUTTON, "%d", button);
+        }
+    }
+}
+
 /**
  * shell_global_play_theme_sound:
  * @global: the #ShellGlobal
  * @id: an id, used to cancel later (0 if not needed)
  * @name: the sound name
+ * @for_event: (allow-none): a #ClutterEvent in response to which the sound is played
  *
  * Plays a simple sound picked according to Freedesktop sound theme.
  * Really just a workaround for libcanberra not being introspected.
  */
 void
-shell_global_play_theme_sound (ShellGlobal *global,
-                               guint        id,
-                               const char  *name)
+shell_global_play_theme_sound (ShellGlobal  *global,
+                               guint         id,
+                               const char   *name,
+                               const char   *description,
+                               ClutterEvent *for_event)
 {
-  ca_context_play (global->sound_context, id, CA_PROP_EVENT_ID, name, NULL);
+  ca_proplist *props;
+
+  ca_proplist_create (&props);
+  build_ca_proplist_for_event (props, name, description, for_event);
+
+  ca_context_play_full (global->sound_context, id, props, NULL, NULL);
+
+  ca_proplist_destroy (props);
+}
+
+/**
+ * shell_global_play_theme_sound_full:
+ * @global: the #ShellGlobal
+ * @id: an id, used to cancel later (0 if not needed)
+ * @name: the sound name
+ * @description: the localized description of the event that triggered this alert
+ * @for_event: (allow-none): a #ClutterEvent in response to which the sound is played
+ * @application_id: application on behalf of which the sound is played
+ * @application_name:
+ *
+ * Plays a simple sound picked according to Freedesktop sound theme.
+ * Really just a workaround for libcanberra not being introspected.
+ */
+void
+shell_global_play_theme_sound_full (ShellGlobal  *global,
+                                    guint         id,
+                                    const char   *name,
+                                    const char   *description,
+                                    ClutterEvent *for_event,
+                                    const char   *application_id,
+                                    const char   *application_name)
+{
+  ca_proplist *props;
+
+  ca_proplist_create (&props);
+  build_ca_proplist_for_event (props, name, description, for_event);
+  ca_proplist_sets (props, CA_PROP_APPLICATION_ID, application_id);
+  ca_proplist_sets (props, CA_PROP_APPLICATION_NAME, application_name);
+
+  ca_context_play_full (global->sound_context, id, props, NULL, NULL);
+
+  ca_proplist_destroy (props);
 }
 
 /**
index 7c14892ddc2b2cfa9b573b821a350049d395bfa5..2dd98ef76d1a1b427c3256d102e348503e74ab89 100644 (file)
@@ -121,9 +121,18 @@ void     shell_global_sync_pointer              (ShellGlobal  *global);
 GAppLaunchContext *
          shell_global_create_app_launch_context (ShellGlobal  *global);
 
-void     shell_global_play_theme_sound          (ShellGlobal  *global,
+void     shell_global_play_theme_sound          (ShellGlobal *global,
+                                                 guint        id,
+                                                 const char   *name,
+                                                 const char   *description,
+                                                 ClutterEvent *for_event);
+void     shell_global_play_theme_sound_full     (ShellGlobal  *global,
                                                  guint         id,
-                                                 const char   *name);
+                                                 const char   *name,
+                                                 const char   *description,
+                                                 ClutterEvent *for_event,
+                                                 const char   *application_id,
+                                                 const char   *application_name);
 void     shell_global_cancel_theme_sound        (ShellGlobal  *global,
                                                  guint         id);